//
//  XSStatus.swift
//  WeiDo
//
//  Created by XISHAN on 16/3/6.
//  Copyright © 2016年 XISHAN. All rights reserved.
//

import UIKit

class XSStatus: NSObject {

    
    // 如果定义成 Int,在32位的系统架构上为Int32,其最大值是没有微博的id大的,是装不下
    var id: Int64 = 0
    // 微博内容
    var text:String?
    // 评论数量
    var comments_count: Int = 0
    // 转发数量
    var reposts_count: Int = 0
    // 点赞数量
    var attitudes_count: Int = 0
    // 当前发送此条微博的用户信息
    var user: XSUser?
    //当前微博创建时间
    var created_at: String?{
        didSet{
            createdDate = NSDate.originalDateWithString(created_at)
        }
    }
    
    
    //当前微博的创建时间(NSDate类型)
    var createdDate:NSDate?
    //微博来源
    var source: String?
    
    // 转发微博
    var retweeted_status: XSStatus?
    
    // 微博配图s
    var pic_urls: [XSPictureModel]?

//    var id: Int = 0
//
//    var mid: String?
//
//    var in_reply_to_screen_name: String?
//
//    var in_reply_to_status_id: String?
//
//    var geo: String?
//
//    var annotations: [String]?
//
//    var in_reply_to_user_id: String?
//
//    var favorited: Bool = false
//
//    var truncated: Bool = false
    
    init(dict:[String : AnyObject]){
        
        super.init()
        
        setValuesForKeysWithDictionary(dict)
        
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            
            guard let v = value as? [String : AnyObject] else{
                return
            }
            user = XSUser(dict: v)
        }
        else if key == "retweeted_status" {
            guard let v = value as? [String: AnyObject] else {
                return
            }
            retweeted_status = XSStatus(dict: v)
        }else if key == "pic_urls" {
            guard let values = value as? [[String: AnyObject]] else {
                return
            }
            // 定义临时数组,以记录字典转模型的结果
            var tempArray = [XSPictureModel]()
            for v in values {
                // 字典转模型
                let pictureModel = XSPictureModel(dict: v)
                tempArray.append(pictureModel)
            }
            self.pic_urls = tempArray
        }else{
            
            super.setValue(value, forKey: key)
        }
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    
}



